
import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

//登录和注册和找回密码
const RegisterStu = () => import("views/log/RegisterStu.vue")
const Login = () => import("views/log/Login.vue")
const Reset = () => import("views/log/Reset.vue")

//<main>标签的wrap
const AdminMain = () => import("views/admin/adminWrap.vue")

//用户管理
const StudentInfo = () => import("views/admin/StudentInfo.vue")
const TeacherInfo = () => import("views/admin/TeacherInfo.vue")

//项目管理
const TK= () => import("views/admin/TK.vue")
const editTK= () => import("views/admin/editTK.vue")

//班级管理
const ClassInfo = () => import("views/admin/ClassInfo.vue")

const SubjectInfo = () => import("views/admin/SubjectInfo.vue")

//前台主界面
const MainPage = () => import("views/main/mainPage.vue")
const MainDoTk =() => import("views/main/mainDoTk.vue")

const routes = [
  {
    path: "",
    redirect: "/login",
  },
  {
    path:"/log",
    redirect:"/login"
  },
  {
    path: "/login",
    name:"login",
    component:Login,
    meta: {
      title: "现场集中管理平台",
    },
  },
  {
    path:"/reg",
    redirect:"/register"
  },
  {
    path:"/register",
    name:"register",
    component:RegisterStu,
    meta:{
      title:"注册 | 学生"
    }
  },
  {
    path:"/reset",
    name:"reset",
    component:Reset,
    meta:{
      title:"找回密码 "
    }
  },
  {
    path:"/admin",
    component:AdminMain,
    children:[
      {
        path:"",
        redirect:"studentInfo"
      },
      {
        path: "studentInfo",
        name:"studentInfo",
        component:StudentInfo,
      },
      {
        path: "teacherInfo",
        name:"teacherInfo",
        component:TeacherInfo,
      },
      {
        path: "subjectInfo",
        name:"subjectInfo",
        component:SubjectInfo,
      },
      {
        path: "classInfo",
        name:"classInfo",
        component:ClassInfo,
      },
      {
        path: "TK",
        name:"TK",
        component:TK,
      },
      {
        path:'TK/:tk_id',
        name:'editTK',
        component: editTK,
      },
    ],
  },
  {
    path:'/main',
    name:'mainPage',
    component: MainPage,
  },
  {
    path:"/main/Tk/:tk_id",
    name:"mainDoTk",
    component:MainDoTk,
  },
];

const router = new VueRouter({
  routes,
});

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  console.log('routerName:'+to.name)
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  // console.log(token,to.path);
  let token = sessionStorage.getItem("token")
  if(!token && to.path != "/login"){
    next("/login")
  }
  next();
});

export default router;
